const webpack = require('webpack')
const path = require('path')

function resolve(dir) {
    return path.join(__dirname, dir)
    // return path.resolve(__dirname, dir)
}
module.exports = {
    css: {
      loaderOptions: {
        less: {
          javascriptEnabled: true
        }
      }
    },
    chainWebpack: config => {
      config.resolve.alias
        .set('@', resolve('src'))
        .set('@@', resolve('src/components'))
        .set('assets', resolve('src/assets'))
        .set('css', resolve('src/assets/css'))
        .set('images', resolve('src/assets/images'))
        .set('views', resolve('src/views'))
        .set('pages', resolve('src/pages'))
        .set('components', resolve('src/components'))
        .set('api', resolve('src/api'))
        .set('mixins', resolve('src/mixins'))
        .set('store', resolve('src/store'))
        .set('service', resolve('src/service'))
    },
    configureWebpack: {
        plugins: [
            new webpack.ProvidePlugin({
                $: "jquery",
                jQuery: "jquery",
                "windows.jQuery": "jquery"
            })
        ]
    },
    // configureWebpack: {
    //     resolve: {
    //         extensions: ['.js', '.vue', '.json'],
    //         alias: {
    //             '@': resolve('src'),
    //             'assets': resolve('src/assets'),
    //             'css': resolve('src/assets/css'),
    //             'images': resolve('src/assets/images'),
    //             'views': resolve('src/views'),
    //             'components': resolve('src/components'),
    //             'api': resolve('src/api'),
    //             'mixins': resolve('src/mixins'),
    //             'store': resolve('src/store'),
    //             'service': resolve('src/service'),
    //         }
    //     }
    // },
    devServer: {
        // proxy,
        host: '0.0.0.0', // 如果是真机测试，就使用这个IP
        port: 6060, // 端口号
        https: false, // https:{type:Boolean}
        hot: true,
        open: false,//'Google Chrome', // 配置自动启动浏览器 true | false
        hotOnly: false, //热更新（webpack已实现了，这里false即可）
        proxy: {
          // 配置跨域，请求后端接口
          '/apiOpen': { // apiOpen为转发路径
            target: 'https://www.apiopen.top',//源地址
            changeOrigin: true, //是否允许跨域
            ws: true, //是否代理 websockets
            pathRewrite: {
              '^/satinApi': ''
            }
          },
          '/apiOpens': { // apiOpens为转发路径
            target: 'https://www.apiopen.top', // 源地址
            secure: false, // 如果是https接口，需要配置这个参数
            changeOrigin: true, //是否允许跨域 | 设置同源 默认false，是否需要改变原始主机头为目标URL
            ws: true, //是否代理 websockets
            pathRewrite: {
              '^/apiOpens': '' // 需要rewrite的
            }
          },
        }
    },
    productionSourceMap: false
}